﻿// ===============================================================================
// XCI.Parent 西安交通信息WinForm开发框架 2019 版权所有
// ===============================================================================

using System;
using System.Threading.Tasks;
using DevExpress.XtraBars;
using XCI.Core;
using XCI.Helper;

namespace XCI.Windows
{
    public partial class FrmReportPreview : BaseForm
    {
        private readonly ReportObject _reportObject;
        private readonly bool allowReportDesign = AppDefaultSettings.AllowCustomReportDesign;
        public FrmReportPreview(ReportObject reportObject)
        {
            InitializeComponent();
            this._reportObject = reportObject;
            //ribbonControl1.Minimized = true;
            barButtonItemDesign.Visibility = WinFormHelper.BarItemVisible(allowReportDesign);
            CreateDocument(_reportObject.Report);
        }

        private void CreateDocument(XtraReportx report)
        {
            this.documentViewer1.PrintingSystem = report.PrintingSystem;
            report.CreateDocument(true);
        }

        private void barButtonItemDesign_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (_reportObject?.Report == null) return;
            _reportObject.Design(() =>
            {
                Task.Delay(500).ContinueWith(p =>
                {
                    _reportObject.Report.CreateDocument(true);
                }, TaskScheduler.FromCurrentSynchronizationContext());
            });
        }
    }
}